<template>
	<view>
		<uni-swipe-action>
		    <view v-for="(item,index) in memberArr" :key="index" @click="setOpened(index)">
				<uni-swipe-action-item :right-options="options" :show="item.isOpened"
			    :auto-close="false" @click="bindClick">
					<groupOrUserItem :avatarUrl="item.avatarUrl" :name="item.nickname"></groupOrUserItem>
				</uni-swipe-action-item>
			</view>
		</uni-swipe-action>
	</view>
	
</template>

<script>
	import {getGroupMemberData} from '@/api/group.js'
	import groupOrUserItem from '../../../src/components/groupOrUserItem/groupOrUserItem.vue'
	export default {
		components: {
		    groupOrUserItem
		},
		onShow() {
			let pages=getCurrentPages()
			this.groupId=pages[pages.length-1].options.groupId
			console.log(this.groupId)
			this.getMembers()
		},
		data() {
			return {
				groupId:null,
				isOpenedArr: [],
				Arr:[
					{
						avatarUrl:'../../static/images/gugou/icon2.png',
						nickname:'111',
						groupName:'乌鸦饲养协会',
						isOpened:'none'
					},
					{
						avatarUrl:'../../static/images/gugou/icon1.png',
						nickname:'222',
						groupName:'爱生活lovelive',
						isOpened:'none'
					},
				],
				memberArr:[],
				options:[
				         {
				            text: '移出该团',
				            style: {
				                backgroundColor: '#dd524d'
				            }
				        }
				],
			};
		},
		methods:{
			setOpened(index) {
				if (this.memberArr[index].isOpened === 'none') {
					this.memberArr[index].isOpened = 'right';
					return;
				}
				if (this.memberArr[index].isOpened === 'right') {
					this.memberArr[index].isOpened = 'none';
					return;
				}
			},
			bindClick(e) {
				console.log(e);
				// uni.showToast({
				// 	title: `点击了${e.position === 'left' ? '左侧' : '右侧'} ${e.content.text}按钮`,
				// 	icon: 'none'
				// });
			},
			getMembers(){
				getGroupMemberData(this.groupId).then(res=>{
					if(res.data.code==200){
						this.memberArr=res.data.data
						this.memberArr.forEach(item=>{
							item.isOpened="none"
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
</style>
